import request from '@/utils/request'
import { TrademarkResponseData, Trademark, TrademarkListResponseData } from './type.ts'
enum API {
  // 品牌列表
  TRADEMARK_URL = '/admin/product/baseTrademark/',

  // 添加品牌 post
  ADD_TRADEMARK_URL = '/admin/product/baseTrademark/save',

  // 修改品牌 PUT
  UPDATE_TRADEMARK_URL = '/admin/product/baseTrademark/update',

  // 删除品牌DELETE /admin/product/baseTrademark/remove/{id}
  DELETE_TRADEMARK_URL = '/admin/product/baseTrademark/remove',

  // 获取品牌列表
  GET_TRADEMARK_LIST_URL =  '/admin/product/baseTrademark/getTrademarkList'
}

export const reqGetTrademarkList = () => {
  return request.get<any, TrademarkListResponseData>(API.GET_TRADEMARK_LIST_URL)
}

export const reqHasTrademark = (page: number, limit: number) => {
  return request.get<any, TrademarkResponseData>(
    API.TRADEMARK_URL + `${page}/${limit}`,
  )
}

export const reqAddOrUpdateTrademark = (data: Trademark) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATE_TRADEMARK_URL, data)
  } else {
    return request.post<any, any>(API.ADD_TRADEMARK_URL, data)
  }
}

export const reqDeleteTrademark = (id: number) => {
  return request.delete<any, any>(API.DELETE_TRADEMARK_URL + `/${id}`)
}
